package com.lyf.shop.services.Impl;

import com.lyf.shop.dao.AddressDao;
import com.lyf.shop.dao.Impl.AddressDaoImpl;
import com.lyf.shop.entity.Address;
import com.lyf.shop.services.AddressService;

import java.sql.SQLException;
import java.util.List;

public class AddressServiceImpl implements AddressService {
    AddressDao addressDao = new AddressDaoImpl();
    @Override
    public List<Address> getAddressByUid(int uid) {
        try {
            if(uid>0){
                return addressDao.getAddressByUid(uid);
            }
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        return null;
    }

    @Override
    public int insertAddr(Address address) {
        try {
            if(address!=null){
                return addressDao.insertAddr(address);
            }
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        return 0;
    }

    @Override
    public int delAddr(int aid) {
        try {
            if(aid>0){
                return addressDao.delAddr(aid);
            }
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        return 0;
    }

    @Override
    public int updateAddr(Address address) {
        try {
            if(address!=null){
                return addressDao.updateAddr(address);
            }
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        return 0;
    }

    @Override
    public int changeAddrToCommons(int aid, int uid) {
        try {
            if (aid>0){
                addressDao.changeAddrToDefault(aid);
                addressDao.changeAddrToCommons(aid,uid);
            }
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        return 0;
    }
}
